//
//  HMWelcomeViewController.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/9.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
import SDWebImage

class HMWelcomeViewController: UIViewController {

   lazy var icovewImage : UIImageView = {
    
        let image = UIImage(named: "ad_background")
        let icovew = UIImageView(image: image)
    
        return icovew
    }()
    lazy var headImage : UIImageView = {
        let imageview = UIImageView()
        imageview.sd_setImageWithURL(NSURL(string: (HMusercount.shareuserCount.userAccount?.avatar_large)!), placeholderImage: UIImage(named: "avatar_default_big"))
        imageview.cornerRadius = 40
        return imageview
    }()
   
    lazy var welcomeLable : UILabel = {
        let lable = UILabel()
        
        lable.font = UIFont.systemFontOfSize(15)
        lable.textColor = UIColor.blackColor()
        lable.text = "欢迎回来"
        lable.alpha = 0
        return lable
    }()
    override func loadView() {
        
        view = icovewImage
        setupUI()
    }
    
    /**
    初始化视图控件
    */
    func setupUI() {
        
        self.view .addSubview(headImage)
        self.view .addSubview(welcomeLable)
        
        
        headImage.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self.view.snp_centerX)
            make.top.equalTo(self.view.snp_top).offset(200)
            make.size.equalTo(CGSize(width: 80, height: 80))
        }
        welcomeLable.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(20)
        }
    
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        
        UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
            UIView.animateWithDuration(1, animations: { () -> Void in
                self.welcomeLable.alpha = 1
                
                }, completion: { (_) -> Void in
                    
                NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchRootVCNotifation, object: self)
            })
                
        }
        
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        

    }
}
